Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var e = require("../../@babel/runtime/helpers/classCallCheck"), t = require("../../@babel/runtime/helpers/createClass"), o = require("../../@babel/runtime/helpers/inherits"), n = require("../../@babel/runtime/helpers/createSuper"), i = null;

try {
    i = requirePlugin("adbright-ad").ADRootService;
} catch (e) {}

var r = function(r) {
    o(a, i);
    var s = n(a);
    function a(t) {
        var o;
        return e(this, a), (o = s.call(this, t)).__modules = {}, o;
    }
    return t(a, [ {
        key: "sendRequest",
        value: function(e) {
            var t = e.url, o = e.data, n = e.header, i = void 0 === n ? {
                "content-type": "application/x-www-form-urlencoded"
            } : n, r = e.timeout, s = void 0 === r ? 3e4 : r, a = e.method, u = void 0 === a ? "GET" : a, l = e.dataType, d = void 0 === l ? "json" : l;
            return new Promise(function(e, n) {
                wx.request({
                    url: t,
                    data: o,
                    header: i,
                    timeout: s,
                    method: u,
                    dataType: d,
                    success: function(t) {
                        200 === t.statusCode && 200 === t.data.code ? e(t.data) : n(t.data);
                    },
                    fail: function(e) {
                        n(e);
                    }
                });
            });
        }
    }, {
        key: "request",
        value: function(e) {
            var t = this;
            return new Promise(function(o, n) {
                wx.getNetworkType().then(function(i) {
                    var r = i.networkType;
                    t.sendRequest(t.addCommonQuery(e, t.createNetworkParam({
                        connect_type: r
                    }))).then(o).catch(n);
                }).catch(function(e) {
                    console.log(e);
                });
            });
        }
    }, {
        key: "navigateTo",
        value: function(e) {
            var t = e.url;
            return wx.navigateTo({
                url: t
            });
        }
    }, {
        key: "navigateToMiniProgram",
        value: function(e) {
            return wx.navigateToMiniProgram(e);
        }
    }, {
        key: "addListeners",
        value: function(e) {
            return e.listeners = {
                onLoad: function() {},
                onShow: function() {},
                onError: function() {},
                onClose: function() {}
            }, e;
        }
    }, {
        key: "createWeixinMotivation",
        value: function(e, t, o) {
            try {
                if (!t.unitId) return;
                this.destroyMotivation(e);
                var n = null;
                if (wx.createRewardedVideoAd) {
                    n = wx.createRewardedVideoAd({
                        adUnitId: t.unitId,
                        multiton: t.multiton || !1
                    });
                    var i = this.addListeners({
                        videoAd: n
                    });
                    return n.onLoad(function() {
                        i.listeners.onLoad();
                    }), n.onError(function(e) {
                        i.listeners.onError(e);
                    }), n.onClose(function(e) {
                        i.listeners.onClose(e);
                    }), this.__modules[e] = i, "function" == typeof o && o(n), i;
                }
            } catch (e) {
                console.log(e);
            }
        }
    }, {
        key: "showMotivation",
        value: function(e, t) {
            var o = this;
            try {
                if (this.__modules[e]) {
                    var n = this.__modules[e].videoAd, i = this.__modules[e].listeners;
                    return n.load().then(function() {
                        n.show().then(function() {
                            console.log("广告显示1"), i.onShow();
                        }).catch(function() {
                            console.log("videoAd.isReady: ", n.isReady()), n.isReady() || o.showMotivationAgain(e);
                        });
                    }).catch(function(e) {
                        i.onError(e);
                    }), this.__modules[e];
                }
                if (t) return this.createWeixinMotivation(t, e, function() {
                    o.showMotivation(e);
                });
            } catch (e) {
                console.log(e);
            }
        }
    }, {
        key: "showMotivationAgain",
        value: function(e) {
            if (this.__modules[e]) {
                var t = this.__modules[e].videoAd, o = this.__modules[e].listeners;
                console.log("videoAd.isReady: ", t.isReady()), t.load().then(function() {
                    t.show().then(function() {
                        console.log("广告显示2"), o.onShow();
                    }).catch(function(e) {
                        console.log("videoAd.isReady: ", t.isReady()), o.onError(e);
                    });
                }).catch(function(e) {
                    o.onError(e);
                });
            }
        }
    }, {
        key: "destroyMotivation",
        value: function(e) {
            var t = this.__modules[e];
            t && (t.videoAd.destory(), delete this.__modules[e]);
        }
    }, {
        key: "createWeixinInterstitial",
        value: function(e, t, o) {
            try {
                if (!t.unitId) return;
                this.destroyInterstital(e);
                var n = null;
                if (wx.createInterstitialAd) {
                    n = wx.createInterstitialAd({
                        adUnitId: t.unitId
                    });
                    var i = this.addListeners({
                        interstitialAd: n
                    });
                    return n.onLoad(function() {
                        i.listeners.onLoad();
                    }), n.onError(function(e) {
                        i.listeners.onError(e);
                    }), n.onClose(function(e) {
                        i.listeners.onClose(e);
                    }), n.load(), this.__modules[e] = i, "function" == typeof o && o(n), i;
                }
            } catch (e) {
                console.log(e);
            }
        }
    }, {
        key: "showInterstital",
        value: function(e, t) {
            var o = this;
            try {
                if (this.__modules[e]) {
                    var n = this.__modules[e].interstitialAd, i = this.__modules[e].listeners;
                    return console.log(n.getSplashAdShowStatus()), n.getSplashAdShowStatus() ? n.show().then(function() {
                        console.log("广告显示1"), i.onShow();
                    }).catch(function(e) {
                        i.onError(e);
                    }) : n.load().then(function() {
                        n.show().then(function() {
                            console.log("广告显示1"), i.onShow();
                        }).catch(function(e) {
                            i.onError(e);
                        });
                    }).catch(function(e) {
                        i.onError(e);
                    }), this.__modules[e];
                }
                if (t) return this.createWeixinInterstitial(t, e, function() {
                    o.showInterstital(e);
                });
            } catch (e) {
                console.log(e);
            }
        }
    }, {
        key: "destroyInterstital",
        value: function(e) {
            var t = this.__modules[e];
            t && (t.interstitialAd.destory(), delete this.__modules[e]);
        }
    } ]), a;
}();

exports.default = r;